package com.collections;

import java.util.HashMap;

import static com.collections.excercises.MemoryConsumtion.*;

public class CompactHashMapMemoryComparator {
	
	private static int MAX_SIZE = 1_000_000;
	
	public static void main(String[] args) {
		System.out.println("=========\nHashMap\n");
		setDiffBeforeAllocate(getMemoryInfo());
		fillStructure( new HashMap<Integer,Integer>(),MAX_SIZE);
		handleAfterAllocate();
		
		System.gc();
		
		System.out.println("=========\nCompactHashMap\n");
		setDiffBeforeAllocate(getMemoryInfo());
		fillStructure( new CompactHashMap(),MAX_SIZE);
		handleAfterAllocate();
		
		System.gc();
		
	}
	
}

/* Results of the following input

=========
HashMap

Total: 16252928
Free: 15956808
Difference: 296120

Total: 65490944
Free: 2201336
Difference: 63289608

Array difference: 62993488

Approximate size per element: 62

=========
CompactHashMap

Total: 65490944
Free: 63663744
Difference: 1827200

Total: 65490944
Free: 33435320
Difference: 32055624

Array difference: 30228424

Approximate size per element: 30


*/
